package com.linln.wxapi;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.linln.common.utils.ResultVoUtil;
import com.linln.common.vo.ResultVo;
import com.linln.modules.help.domain.HelpInfo;
import com.linln.modules.help.service.HelpInfoService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 相关小程序接口
 * @author hct
 *
 */
@Api(value="帮助类信息管理")
@Controller
@RequestMapping("/wx/info/{area}")
public class WxApiInfoController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private HelpInfoService infoService;

    /**
     * 获取帮助信息列表
     * @return
     */
    /* @ApiOperation(value = "获取信息列表",  notes = "获取信息列表")
     @ApiImplicitParams({
          @ApiImplicitParam(name = "list", value = "获取区域信息",paramType = "query", required = true, dataType = "int")
     })
     @RequestMapping(value = "/list",method={RequestMethod.POST,RequestMethod.GET})
     @ResponseBody
     public ResultVo helplist(@PathVariable String area, Integer typeid) {
        
         try {
         	// 创建匹配器，进行动态查询匹配
             ExampleMatcher matcher = ExampleMatcher.matching();
                     //.withMatcher("type_name", match -> match.contains())
              HelpInfo info=new HelpInfo();
              info.setTypeid(1L);
             // 获取数据列表
             Example<HelpInfo> example = Example.of(info, matcher);
             //Sort sort = new Sort(Sort.Direction.ASC, "id");
             Page<HelpInfo> list = infoService.getPageList(example);
             Map<String,Object> map=new HashMap<String,Object>();
             map.put("list", list.getContent());
             map.put("pageNumber", list.getPageable().getPageNumber()+1);
             map.put("pageSize", list.getPageable().getPageSize());
             return ResultVoUtil.success(map);
         } catch (Exception e) {
             this.logger.error(e.getMessage(), e);
             return ResultVoUtil.error("接口异常"); 
         }
     }*/
     
     
     /**
      * 获取帮助信息列表
      * @return
      */
      @ApiOperation(value = "获取信息列表",  notes = "获取信息列表")
      @ApiImplicitParams({
           @ApiImplicitParam(name = "list", value = "获取区域信息",paramType = "query", required = true, dataType = "int")
      })
      @RequestMapping(value = "/list",method={RequestMethod.POST,RequestMethod.GET})
      public String helplist(@PathVariable String area, Integer typeid,Model model) {
          	// 创建匹配器，进行动态查询匹配
              ExampleMatcher matcher = ExampleMatcher.matching();
                      //.withMatcher("type_name", match -> match.contains())
               HelpInfo info=new HelpInfo();
               info.setTypeid(1L);
              // 获取数据列表
              Example<HelpInfo> example = Example.of(info, matcher);
              //Sort sort = new Sort(Sort.Direction.ASC, "id");
              Page<HelpInfo> list = infoService.getPageList(example);
              model.addAttribute("list", list);
              return "/front/info/list";
           
      }
      
     
     /**
      * 获取关于我们信息
      * id=1
      * @return
      */
      /*@ApiOperation(value = "获取关于信息列表",  notes = "获取我们信息列表")
      @ApiImplicitParams({
           @ApiImplicitParam(name = "about", value = "获取关于我们信息",paramType = "query", required = true, dataType = "int")
      })
      @RequestMapping(value = "/about",method={RequestMethod.POST,RequestMethod.GET})
      @ResponseBody
      public ResultVo arealist(@PathVariable String area, Long id) {
         
          try {
          	  HelpInfo info = infoService.getById(id);
              return ResultVoUtil.success(info);
          } catch (Exception e) {
              this.logger.error(e.getMessage(), e);
              return ResultVoUtil.error("接口异常"); 
          }
      }*/
      
      /**
       * 获取关于我们信息
       * id=1
       * @return
       */
       @ApiOperation(value = "获取关于信息",  notes = "获取我们信息")
       @ApiImplicitParams({
            @ApiImplicitParam(name = "about", value = "获取关于我们信息",paramType = "query", required = true, dataType = "int")
       })
       @RequestMapping(value = "/about",method={RequestMethod.POST,RequestMethod.GET})
        public String about(@PathVariable String area, Long id,Model model) {
          
             HelpInfo info = infoService.getById(id);
           	 model.addAttribute("info", info);
             return "/front/info/about";
            
       }
       /**
        * 获取关于我们信息
        * id=1
        * @return
        */
        @ApiOperation(value = "获取入住商户协议信息",  notes = "获取入住商户协议信息")
        @ApiImplicitParams({
             @ApiImplicitParam(name = "xieyi", value = "获取信息",paramType = "query", required = true, dataType = "int")
        })
        @RequestMapping(value = "/xieyi",method={RequestMethod.POST,RequestMethod.GET})
         public String xieyi(@PathVariable String area, Long id,Model model) {
           
              HelpInfo info = infoService.getById(id);
            	 model.addAttribute("info", info);
              return "/front/info/xieyi";
             
        }
        
        
        /**
         * 获取帮助信息列表
         * @return
         */
        @ApiOperation(value = "获取公告列表",  notes = "获取公告列表")
         @ApiImplicitParams({
              @ApiImplicitParam(name = "bulletin", value = "获取区域信息",paramType = "query", required = true, dataType = "int")
         })
         @RequestMapping(value = "/bulletin",method={RequestMethod.POST,RequestMethod.GET})
         @ResponseBody
         public ResultVo bulletinlist(@PathVariable String area, Integer typeid) {
            
             try {
             	// 创建匹配器，进行动态查询匹配
                 ExampleMatcher matcher = ExampleMatcher.matching();
                         //.withMatcher("type_name", match -> match.contains())
                  HelpInfo info=new HelpInfo();
                  info.setTypeid(3L);
                 // 获取数据列表
                 Example<HelpInfo> example = Example.of(info, matcher);
                 //Sort sort = new Sort(Sort.Direction.ASC, "id");
                 Page<HelpInfo> list = infoService.getPageList(example);
                 Map<String,Object> map=new HashMap<String,Object>();
                 map.put("list", list.getContent());
                 map.put("pageNumber", list.getPageable().getPageNumber()+1);
                 map.put("pageSize", list.getPageable().getPageSize());
                 return ResultVoUtil.success(map);
             } catch (Exception e) {
                 this.logger.error(e.getMessage(), e);
                 return ResultVoUtil.error("接口异常"); 
             }
         }
        
        /**
         * 获取关于我们信息
         * id=1
         * @return
         */
         @ApiOperation(value = "获取关于信息",  notes = "获取我们信息")
         @ApiImplicitParams({
              @ApiImplicitParam(name = "bulletindetail", value = "获取关于我们信息",paramType = "query", required = true, dataType = "int")
         })
         @RequestMapping(value = "/bulletin/detail",method={RequestMethod.POST,RequestMethod.GET})
          public String bulletindetail(@PathVariable String area, Long id,Model model) {           
               HelpInfo info = infoService.getById(id);
             	 model.addAttribute("info", info);
               return "/front/info/bulletin";
              
         }
}
